<template>
	<view>
		<!-- 状态栏 -->
		<view class="statusBar" :style="'height:'+statusBarHeight+'px'"></view>
		<view class="myheader padding-sm  flex justify-between">
			<view class="font-sub-title">
				<text class="cuIcon-back margin-right-ssm" @click="back()"></text>
				防丢提醒
			</view>
			<text class="font-sub-title" @click="save()">保存</text>
		</view>
		<view class="cu-list menu">
			<view class="cu-item">
				<view class="content">
					防丢提醒
				</view>
				<view class="action">
					<switch class="blue" @change="open" :class="isopen?'checked':''" :checked="isopen"></switch>
				</view>
			</view>
			<view class="cu-item">
				<view class="content">
					寻找手环
				</view>
				<view class="action">
					<button class="cu-btn" @click="findDevice()">震动</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const bandSDK = uni.requireNativePlugin('BandSDK')
	var that;
	export default {
		data() {
			return {
				statusBarHeight: Vue.prototype.StatusBar,
				isopen:uni.getStorageSync("antiloseOpen")||false
			}
		},
		onLoad() {
			that=this;
		},
		methods: {
			back(){
				uni.navigateBack();
			},
			open(e){
				this.isopen=e.target.value
			},
			findDevice(){
				bandSDK.appFindDevice({
					mode:1,
					remindNum:3,
					remindInterval:2
				},res=>{
				})
			},
			save(){
				var type =0
				if(this.isopen){
					type = 2
				}
				bandSDK.settingAntiLose({
					type:type
				},res=>{
					if(res=='success'){
						uni.setStorageSync("antiloseOpen",that.isopen)
						uni.showToast({
							title:"保存成功"
						})
					}
				})
			}
		}
	}
</script>

<style>

</style>
